package satir.card;

import java.util.Observable;
import java.util.Observer;

import satir.framework.LazyInitiator;
import satir.player.Player;

/**
 * The Class Card.
 * @version 3.0 April 2012
 * @author Creative Family
 */
public abstract class Card {

    /**
     * The Class AfterActivateCardObservable.
     */
    public class AfterActivateCardObservable extends Observable {

	/**
	 * Trigger.
	 * @param o
	 *        the object
	 */
	public void trigger(final Object o) {
	    this.setChanged();
	    this.notifyObservers(o);
	}
    }

    /** The card name. */
    protected String name;

    /** The key. */
    protected String key;

    /** The observe after activate card. */
    private AfterActivateCardObservable observeAfterActivateCard;

    /**
     * Instantiates a new card.
     */
    public Card() {
    }

    /**
     * Instantiates a new card.
     * @param key
     *            the key
     * @param name
     *            the card name
     */
    public Card(final String key, final String name) {
	observeAfterActivateCard = new AfterActivateCardObservable();
	observeAfterActivateCard.addObserver((Observer) LazyInitiator.get(
		"GameRecord", "GameRecord"));
	this.name = name;
	this.key = key;
    }

    /**
     * The action after activate card.
     */
    protected void afterActivateCard() {
	observeAfterActivateCard.trigger(this);
    }

    /**
     * Activate card.
     * @param p
     *        the player object for card operation
     */
    public void activateCard(final Player p) {
	doActivateCard(p);
	afterActivateCard();
    }

    /**
     * Do activate card.
     * @param p
     *        the player object
     */
    protected abstract void doActivateCard(Player p);

    /**
     * Sets the card name.
     * @param name
     *            the new card name
     */
    public void setName(final String name) {
	this.name = name;
    }

    /**
     * Gets the card name.
     * @return the card name
     */
    public String getName() {
	return this.name;
    }
}
